#include <iostream>
#include <math.h>
#include <set>

using namespace std;
bool pandigital( long int a,  long int b, long int ab);
void Digitos(long int n,set<int>& dig,int dim);
int main()
{

    set<long long int> conjunto;
    set<long long int>::iterator it;

    for (int a= 2;a < 100000 ; a++)
    {

        for (int b = 1; a*b < 100000 ; b++)
        {
            if (pandigital(a,b,a*b)) conjunto.insert(a*b);

        }

    }
    long long int sum = 0;

    for (it = conjunto.begin();it != conjunto.end() ;it++ )
        sum = sum + *it;

    cout << sum;
    return 0;
}

bool pandigital( long int a,  long int b, long int ab)
{
    int dimA, dimB, dimAB;
    set<int> dig;
    set<int>::iterator it;

    dimA = log10(a) + 1;
    dimB = log10(b) + 1;
    dimAB = log10(ab) + 1;

    if (dimA + dimB + dimAB == 9)
    {

        Digitos(a,dig,dimA);
        Digitos(b,dig,dimB);
        Digitos(ab,dig,dimAB);
        if (dig.size() == 9 and dig.count(0) == 0)
        {
                        cout <<"(" <<a  << "*"<< b << "="<< a*b << ")"<< endl;

            return true;

        }
        else return false;
    }
    else return false;

}


void Digitos(long int n,set<int>& dig,int dim)
{


    while (n>0)
    {
        dig.insert(n % 10);
        n = static_cast<int>(n /10);

    }
}
